home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / source / gfxfx / makearry.pas < prev    next >
Pascal/Delphi Source File  |  1994-04-20  |  2KB  |  72 lines

  1.  
  2. program MakeArrayFromBintable;
  3. { you know the drill... }
  4. uses
  5.   crt,dos;
  6.  
  7. var
  8.   InFile : file of byte;
  9.   OutFile : text;
  10.   FileName : pathstr;
  11.   I,Size,TotalSize : longint;
  12.   J : word;
  13.   InByte,Len : byte;
  14.  
  15. function ValLen(Num : byte) : byte; begin
  16.   if Num <> 0 then ValLen := round(ln(Num)/2.303)+1 else ValLen := 1; end;
  17.  
  18. begin
  19.   writeln;
  20.   if paramstr(1) = '' then begin
  21.     write('Enter Filename: ');
  22.     readln(FileName);
  23.   end else FileName := paramstr(1);
  24.  
  25.   assign(InFile,FileName);
  26.   reset(InFile);
  27.   seek(InFile,$20); { <-- Put filepointer after mess-header! }
  28.   Size := filesize(InFile);
  29.   assign(OutFile,'ARRAY.INC');
  30.   rewrite(OutFile);
  31.   writeln(OutFile,'  PicArray : array[0..TotalSize] of byte = (');
  32.   write(OutFile,'    ');
  33.   TotalSize := 0; I := 0; Len := 4;
  34.   while not eof(InFile) do begin
  35.     read(InFile,InByte);
  36.     write(OutFile,InByte,',');
  37.     inc(Len,ValLen(InByte)+1);
  38.     inc(TotalSize);
  39.  
  40.     if InByte = 0 then begin
  41.       J := 1;
  42.       inc(I);
  43.       read(InFile,InByte);
  44.       while (InByte = 0) and (not eof(InFile)) do begin
  45.         inc(J);
  46.         inc(I);
  47.         read(InFile,InByte);
  48.       end;
  49.       write(OutFile,lo(J),',',hi(J),',');
  50.       inc(Len,ValLen(lo(J))+ValLen(hi(J))+2);
  51.       inc(TotalSize,2);
  52.       if InByte <> 0 then begin
  53.         write(OutFile,InByte,',');
  54.         inc(Len,ValLen(InByte)+1);
  55.         inc(TotalSize);
  56.       end;
  57.     end;
  58.  
  59.     if Len > 75 then begin
  60.       writeln(OutFile);
  61.       write(OutFile,'    ');
  62.       Len := 4;
  63.     end;
  64.     inc(I); write(#13,Size-I:6);
  65.   end;
  66.   writeln(OutFile,');');
  67.   writeln(OutFile);
  68.   writeln(OutFile,'  TotalSize = ',TotalSize-1,';');
  69.   close(InFile); close(OutFile);
  70.   writeln;
  71. end.
  72.